import { UserInfo } from '@/interfaces/userManager'
import type { ProColumns } from '@ant-design/pro-components';
import { Button } from 'antd';
import { deleteUser } from '@/services/userManagement'
import showDeleteConfirm from '@/utils/deleteConfirm';
import role_enum from './role';

const getColumns: (changeRoleRef, setId) => ProColumns<UserInfo>[] = (changeRoleRef, setId) => {
    let role = {}
    for (let key in role_enum) {
        role[key] = {
            text: role_enum[key]
        }
    }
    return [
        {
            title: '工号',
            dataIndex: 'jobnumber',
        },
        {
            title: '姓名',
            dataIndex: 'username',
        },
        {
            title: '角色',
            dataIndex: 'role',
            valueType: 'select',
            valueEnum: role,
        },
        {
            title: '手机号',
            dataIndex: 'phone',
            hideInSearch: true,
        },
        {
            title: '注册时间',
            dataIndex: 'createTime',
            hideInSearch: true
        },
        {
            title: '操作',
            valueType: 'option',
            key: 'option',
            render: (text, record, _, action) => [
                <Button
                    size='small'
                    type='primary'
                    key='changeRole'
                    onClick={() => {
                        setId(record.jobnumber)
                        changeRoleRef?.current?.showModelRef();
                    }}
                >
                    修改角色
                </Button>,
                <Button
                    size='small'
                    type='primary'
                    key="deleteUser"
                    danger
                    onClick={() => {
                        showDeleteConfirm({ id: record.jobnumber, action, deleteApi: deleteUser })
                    }}
                >
                    删除
                </Button>,
            ],
        },
    ];
}

export default getColumns;